//
//  SecondViewController.m
//  协议传值<带返回值.
//
//  Created by dllo on 16/8/4.
//  Copyright © 2016年 YMJ. All rights reserved.
//

#import "SecondViewController.h"
#import "NextViewController.h"
#import "BlockViewController.h"

@interface SecondViewController ()
@property (nonatomic, strong) UILabel *label;

@end

@implementation SecondViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake(200, 200, 200, 50);
    button.backgroundColor = [UIColor grayColor];
    [button setTitle:@"今天真是个好日子" forState:0];
    [button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button];
    self.label = [[UILabel alloc] initWithFrame:CGRectMake(200, 400, 300, 50)];
    _label.backgroundColor = [UIColor grayColor];
    _label.textColor = [UIColor blackColor];
    _label.text = @"我是SecVC";
    [self.view addSubview:_label];
    
    
}
- (void)buttonAction:(UIButton *)btn {
    BlockViewController *nextVC = [[BlockViewController alloc] init];
    [nextVC returnTxt:^(NSString *textFieldString, UIColor *textFieldColor) {
        // 回调Block
        NSLog(@"%@",textFieldString);
        _label.text = [NSString stringWithFormat:@"哈哈,%@",textFieldString];
        _label.backgroundColor = textFieldColor;
        
    }];
    [nextVC sendValue:^NSString *{
        // block 没有携带任何东西,废物一个(暂时未知作用)
       return @"不带参数的block不是好block";
    }];
    CATransition *animation = [CATransition animation];
    animation.timingFunction = UIViewAnimationCurveEaseInOut;
    animation.duration = 2;
    animation.type = kCATransitionPush;
    animation.subtype = kCATransitionFromTop;
    [self.view.window.layer addAnimation:animation forKey:@"cc"];
    [self presentViewController:nextVC animated:NO completion:^{
        
        
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
